package com.iwomy.envpro.platform.dto;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.iwomy.envpro.platform.constant.CpEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 设备上报数据
 *
 * @author pig
 * @date 2023-08-29 17:58:11
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "设备上报数据")
public class DeviceDataDTO extends Model<DeviceDataDTO> {
	@JsonProperty("ST")
	//系统编码
	private String st;
	@JsonProperty("MN")
	//设备唯一标识(id)
	private String mn;
	@JsonProperty("SIZE")
	private String size;
	@JsonProperty("PW")
	//访问密码
	private String pw;
	@JsonProperty("DataTime")
	@JsonFormat(pattern = "yyyyMMddHHmmss")
	private LocalDateTime dataTime;
	@JsonProperty("End")
	private String end;
	@JsonProperty("CN")
	//命令编码
	private Integer cn;
	@JsonProperty("QN")
	//请求编码
	private String qn;
	@JsonProperty("Flag")
	private String flag;
	@JsonProperty("CP")
	private JSONObject cp;

	/**
	 * cpCode获取对应的值
	 * @param cpCode
	 * @return
	 */
	public BigDecimal getCpRtd(String cpCode){
		JSONObject cp = this.getCp();
		JSONObject jsonObject = cp.getJSONObject(cpCode);
		if(ObjectUtil.isNull(jsonObject))
			return null;
		return  jsonObject.getBigDecimal("Rtd");
	}
	public String getCpRtdString(String cpCode){
		JSONObject cp = this.getCp();
		JSONObject jsonObject = cp.getJSONObject(cpCode);
		if(ObjectUtil.isNull(jsonObject))
			return null;
		return  jsonObject.getString("Rtd");
	}

	/**
	 * cpCode获取对应的值
	 * @param cpCode
	 * @return
	 */
	public String getCpFlag(String cpCode){
		JSONObject cp = this.getCp();
		JSONObject jsonObject = cp.getJSONObject(cpCode);
		if(ObjectUtil.isNull(jsonObject))
			return null;
		return  jsonObject.getString("Flag");
	}


}